#conding = utf-8
import sys
sys.path.append('D:/seleniumpython')
from selenium import webdriver
import time
from find_element import FindElement

class LoginFunction(object):
    def __init__(self,url):
        self.driver = self.get_driver(url)
    #打开页面
    def get_driver(self,url):
        driver = webdriver.Chrome()
        driver.get(url)
        driver.maximize_window()
        return driver
    
    #获取用户登陆value
    def send_login_value(self,key,data):
        self.get_login_element(key).send_keys(data)



   #定位用户登陆信息
    def get_login_element(self,key):
       find_element = FindElement(self.driver)
       login_element = find_element.get_element(key)
       return login_element

    #执行登陆
    def main(self):
        self.send_login_value("login_name","13524559846")
        self.get_login_element("login_pwd").click()
        self.send_login_value("login_password","qiao2012")
        self.get_login_element("automatic_login").click()
        login_button = self.get_login_element("login_button").click()
        time.sleep(10)
        if login_button == None:
            time.sleep(5)
            self.driver.save_screenshot("D:/seleniumpython/login_success.png")
        



if __name__ == "__main__":
    login_function = LoginFunction("http://my.caissa.com.cn/SignIn/index")
    login_function.main()





